<%@ page language="java" contentType="text/html; charset=utf-8"	pageEncoding="utf-8"%>
<%@page import="java.util.List"%>
<%@page import="java.util.*"%>
<%@page import="org.springframework.web.context.WebApplicationContext"%>
<%@page	import="org.springframework.web.context.support.WebApplicationContextUtils"%>
<%@ page import="java.util.ArrayList"%>

<%@page import="com.yellowpage.white.ui.Menu"%>
<%@page import="com.yellowpage.white.ui.MenuItem"%>

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

<%
	String theme = getServletContext().getInitParameter("white-theme");

	String topImageUrl = "";

	ServletContext sCtx = session.getServletContext();
	WebApplicationContext ctx = WebApplicationContextUtils
			.getRequiredWebApplicationContext(sCtx);

	Menu menu = (Menu) ctx.getBean("menu");

	List menuItemList = menu.getMenuItemList();
%>

<html xmlns="http://www.w3.org/1999/xhtml">

<head>
	<c:set var="ctx" value="${pageContext.request.contextPath}" />
	<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
	<title>menu</title>
	<link href="${ctx}/white/theme/<%=theme%>/css/commen.css" rel="stylesheet" type="text/css" />
	<link href="${ctx}/white/theme/<%=theme%>/css/left.css" rel="stylesheet" type="text/css" />
		
<script language="javascript">
	// JavaScript Document

	var lastFaqClick = null;//上次点击的faq
	window.onload = function() {
		var faq = document.getElementById("div_left");
		var dls = faq.getElementsByTagName("dl");
		
		for ( var i = 0, dl; dl = dls[i]; i++) {
			var dt = dl.getElementsByTagName("dt")[0];//取得标题
			dt.id = "faq_dt_" + (Math.random() * 100);
			dt.onclick = function() {
				var p = this.parentNode;//取得父节点
				if (lastFaqClick != null && lastFaqClick.id != this.id) {
					var dds = lastFaqClick.parentNode.getElementsByTagName("dd");
					
					for ( var i = 0, dd; dd = dds[i]; i++){
						dd.style.display = 'none';
					}
				}
				lastFaqClick = this;
				var dds = p.getElementsByTagName("dd");//取得该父节点所有的子节点，也就是所有的答案
				
				var tmpDisplay = 'none';
				if (gs(dds[0], 'display') == 'none'){
					tmpDisplay = 'block';
				}	
				for ( var i = 0; i < dds.length; i++){
					dds[i].style.display = tmpDisplay;
				}	
		
				var itemDiv = p.getElementsByTagName("div")[0];
				itemDiv.style.height = document.documentElement.clientHeight
						- dls.length * 26 - dds.length * 21 - 30;
			}
		}
		dls[0].getElementsByTagName("dt")[0].click();
	}

	/**
	 *取得元素的真实css属性
	 *written in 06.7 sheneyan
	 */
	function gs(d, a) {
		if (d.currentStyle) {
			var curVal = d.currentStyle[a]
		} else {
			var curVal = document.defaultView.getComputedStyle(d, null)[a]
		}
		return curVal;
	}

	function setNavigator() {	    
		var curMenu = event.srcElement.parentNode.parentNode;
		
		var curTitle = curMenu.getElementsByTagName("dt")[0];//取得标题		
		
		top.header.moduleSpanId.innerText = "->" + curTitle.innerText;
		top.header.funSpanId.innerText = "->" + event.srcElement.innerText;
	}

	function setMain(url) {
		window.top.main.location = url;
	}
</script>

</head>

<body oncontextmenu="return false">		
	<div id="div_left">

<%
	for (int j = 0; j < menuItemList.size(); j++) {
		MenuItem myTopMenu = (MenuItem) menuItemList.get(j);
		List subItems = myTopMenu.getSubMenuItems();
%>
	<dl >
		<dt style="{background:url(<%=topImageUrl%>) no-repeat 10px 2px; }"><%=myTopMenu.getName()%></dt>
	<%
		for (int i = 0; i < subItems.size(); i++) {
				MenuItem subItem = (MenuItem) subItems.get(i);
	%>
		<dd><br/><a href="#" onClick="setMain('${ctx}<%=subItem.getDistination()%>'),setNavigator()"><%=subItem.getName()%></a></dd>
	<%
		}
	%>
		<div>&nbsp;</div>
	</dl>
<%
	}
%> 
 


		</div>
	</body>
</html>
